Annotations
What are annotations for?β
- Annotations in Java are special markers that provide metadata about source code elements. They are introduced with the "@" symbol. They provide additional information that can be interpreted by the compiler, the runtime, or external tools.
ItsMagic annotationsβ
@AutoWiredβ
- Searches and attaches the component to the object where the script is present.
Exampleβ
public class YourClass extends Component {
// creates a new Rigidbody, @Autowired selects the object component
@AutoWired
private Rigidbody rigidbody;
@Override
public void repeat() {
// checking if the screen has been pressed and the Rigidbody is non-null
if (Input.getTouch(0).isDown() && rigidbody != null) Console.log("Rigidbody found!"); // showing a message in the terminal if the conditional is true
}
}
@Singletonβ
- Searches for and attaches the component to the first component of the same type found in the scene.
Exampleβ
public class YourClass extends Component {
// creates a new SUIText, @Singleton selects the first component it finds in the scene
@Singleton
private SUIText text;
@Override
public void repeat() {
// checking if the screen has been pressed and the SUIText is non-null
if (Input.getTouch(0).isDown() && text != null) Console.log("SUIText found!"); // showing a message in the terminal if the conditional is true
}
}
@Hideβ
- Hide variables in the inspector (script properties).
Exampleβ
public class YourClass extends Component {
// creates a new float value, @Hide hides the variable in the inspector (script properties)
@Hide
public float value = 10f;
}
@Orderβ
- Orders variables according to the defined position.
Exampleβ
public class YourClass extends Component {
// creates a new float value, @Order sets the variable position in the inspector to -1
@Order(idx=-1)
public float value1 = 1f;
// creates a new float value, @Order sets the variable position in the inspector to 0
@Order(idx=0)
public float value2 = 2f;
// creates a new float value, @Order sets the variable position in the inspector to 1
@Order(idx=1)
public float value3 = 3f;
// creates a new float value, @Order sets the variable position in the inspector to 2
@Order(idx=2)
public float value4 = 4f;
}
@ReadOnlyβ
- Prevents the variable value from being changed by the inspector (script properties).
Exampleβ
public class YourClass extends Component {
// creates a new float value, @ReadOnly prevents the variable value from being changed by the inspector (script properties)
@ReadOnly
public float value = 10f;
}